#pragma once
#include <qobject.h>
#include <QTcpSocket>
#include <QList>
#include <qbytearray.h>
#include <qcolor.h>

class QCPLayoutGrid;
class QCPAxisRect;
class QCustomPlot;
class QCPTextElement;
class QCPGraph;

class SamplerView :
    public QObject
{
Q_OBJECT
public:
    SamplerView(QCustomPlot* plot,QTcpSocket* socket);
    ~SamplerView();
    QTcpSocket* socket() { return m_socket; }
    QCPAxisRect* axisRect() { return m_qcpRect; }
    QCPLayoutGrid* layout() { return m_qcpLayout; }

private slots:
    void socketStateChanged(QTcpSocket::SocketState state);
    void recvData();

signals:
    void closeRequest();

private:
    bool readPack();
    void initChannels(int channelCount);
    void writeChannelData(qint64 timeStamp, qint32 timeInterval, const QByteArray& channelData);

private:
    //qcp
    QCustomPlot* m_plot;
    QCPLayoutGrid* m_qcpLayout;
    QCPAxisRect* m_qcpRect;
    QCPTextElement* m_qcpTitle;
    QList<QCPGraph*> m_channelGraphs;

    QTcpSocket* m_socket;
    QByteArray m_cache;
};